<?php
class _Page extends TableBase {
	
	function init(){
		$this->addLoaderVariable('id', 'Auto');
		$this->addLoaderVariable('keyword', 'Text', '', '', 11);
		$this->addLoaderVariable('title', 'Text');
		$this->addLoaderVariable('parent', 'ID', '0', 'i');
		$this->addLoaderVariable('url', 'Text');
		$this->addLoaderVariable('hidden', 'Boolean', '0');
	}
	
	function view(){
		F::get()->Tpl()->setTitle($this->title);
		
		$fileName  = $this->keyword;
		if( !file_exists(ROOT.'pages/'.$fileName.'.php') ){
			$fileName = 404;
		}
		
		$className = 'page'.ucFirst($fileName);
		require_once(ROOT.'pages/'.$fileName.'.php');
		
		$class = new $className( $this );
		$class->draw();
	}
	
	function edit( $postdata = array() ){
		$dataFrom = F::get()->DataTypeForms();
		$dataFrom->add('Keyword','keyword',  array('uneditable'=>true));
		$dataFrom->add('Title','title');
		$dataFrom->add('Url','url');
		$dataFrom->add('Hidden','hidden');
		$dataFrom->draw('edit', 'edit', $this, $postdata['token']);
		echo($html);
	}
	
	function post( $postdata ){
		$db = F::get()->DB();
		if( $db->updateViaArray( $postdata['datatypeVal'], $this->_tableName, 'WHERE `id` = "'.$this->id.'"' ) ){
			F::get()->Tpl()->addMessage('Page Settings','Page updated');
		}
	}
	function drawNavLink(){
		echo('<a href="'.(empty($this->url) ? $this->keyword : $this->url).'">'.$this->title.'</a>');
	}
	
	
}
?>
